package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.SysPtScoreVo;
import com.ruoyi.system.bo.SysPtScoreQueryBo;
import com.ruoyi.system.bo.SysPtScoreAddBo;
import com.ruoyi.system.bo.SysPtScoreEditBo;
import com.ruoyi.system.service.ISysPtScoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 学生成绩卡Controller
 *
 * @author 莫修
 * @date 2021-11-28
 */
@Api(value = "学生成绩卡控制器", tags = {"学生成绩卡管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/SysScore")
public class SysPtScoreController extends BaseController {

    private final ISysPtScoreService iSysPtScoreService;

    /**
     * 查询学生成绩卡列表
     */
    @ApiOperation("查询学生成绩卡列表")
    @PreAuthorize("@ss.hasPermi('system:SysScore:list')")
    @GetMapping("/list")
    public TableDataInfo<SysPtScoreVo> list(@Validated SysPtScoreQueryBo bo) {
        return iSysPtScoreService.queryPageList(bo);
    }

    /**
     * 导出学生成绩卡列表
     */
    @ApiOperation("导出学生成绩卡列表")
    @PreAuthorize("@ss.hasPermi('system:SysScore:export')")
    @Log(title = "学生成绩卡", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysPtScoreVo> export(@Validated SysPtScoreQueryBo bo) {
        List<SysPtScoreVo> list = iSysPtScoreService.queryList(bo);
        ExcelUtil<SysPtScoreVo> util = new ExcelUtil<SysPtScoreVo>(SysPtScoreVo.class);
        return util.exportExcel(list, "学生成绩卡");
    }

    /**
     * 获取学生成绩卡详细信息
     */
    @ApiOperation("获取学生成绩卡详细信息")
    @PreAuthorize("@ss.hasPermi('system:SysScore:query')")
    @GetMapping("/{scoreId}")
    public AjaxResult<SysPtScoreVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("scoreId") Long scoreId) {
        return AjaxResult.success(iSysPtScoreService.queryById(scoreId));
    }

    /**
     * 新增学生成绩卡
     */
    @ApiOperation("新增学生成绩卡")
    @PreAuthorize("@ss.hasPermi('system:SysScore:add')")
    @Log(title = "学生成绩卡", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysPtScoreAddBo bo) {
        return toAjax(iSysPtScoreService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改学生成绩卡
     */
    @ApiOperation("修改学生成绩卡")
    @PreAuthorize("@ss.hasPermi('system:SysScore:edit')")
    @Log(title = "学生成绩卡", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody SysPtScoreEditBo bo) {
        return toAjax(iSysPtScoreService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除学生成绩卡
     */
    @ApiOperation("删除学生成绩卡")
    @PreAuthorize("@ss.hasPermi('system:SysScore:remove')")
    @Log(title = "学生成绩卡" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{scoreIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] scoreIds) {
        return toAjax(iSysPtScoreService.deleteWithValidByIds(Arrays.asList(scoreIds), true) ? 1 : 0);
    }
}
